package test;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import dsa.*;

public class ShermanSzetoTest {

	LinkedList list;
	ListIterator iterator;

	@Before
	/**
	Linked List: 
	this is zero 0
	this is first 1
	this is second 2
	I changed this to third 3
	this is fourth 4
	this is fifth 5
	I changed this to sixth 6
	this is seventh 7
	this is Last 8
	 */
	public void setUp() throws Exception {
		list = new LinkedList();


		list.addFirst("this is third");

		list.addLast("this is fourth");
		list.addLast("this is fifth");
		list.addLast("this is sixth");
		list.addLast("this is seventh");
		list.addLast("this is Last");

		list.addFirst("this is second");
		list.addFirst("this is first");
		list.addFirst("this is zero");

		list.addFirst("this is kind of first");
		list.addLast("this is kind of last");

		list.removeFirst();
		list.removeLast();

		list.set(6, "I changed this to sixth");
		list.set(3, "I changed this to third");

	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSize() {
		assertTrue(list.size() == 9);
	}

	@Test
	public void testGet() {
		assertTrue(list.get(6).equals("I changed this to sixth"));
	}

	@Test
	public void testIndexOf() {
		assertTrue(list.indexOf("this is fifth") == 5);
	}

	@Test
	public void testContains() {
		list.removeLast();
		assertTrue(list.contains("this is first") == true);
		assertTrue(list.contains("this is Last") == false);
	}

	@Test
	public void testAddFirst() {
		list.addFirst("A");
		assertTrue(list.getFirst().equals("A"));
	}

	@Test
	public void testAddLast() {
		list.addLast("Z");
		assertTrue(list.getLast().equals("Z"));
	}

	@Test
	public void testRemove() {
		list.remove(4);
		assertTrue(!list.get(4).equals("this is fourth"));
		assertTrue(!(list.size() == 9));
	}

	@Test
	public void testRemoveFirst() {
		assertTrue(!list.getFirst().equals("this is kind of first"));
	}

	@Test
	public void testRemoveLast() {
		assertTrue(!list.getLast().equals("this is kind of last"));
	}

	@Test
	public void testGetFirst() {
		list.addFirst("thisisfirst");
		assertTrue(list.getFirst().equals("thisisfirst"));
	}

	@Test
	public void testGetLast() {
		list.addLast("thisislast");
		assertTrue(!list.getFirst().equals("thisislast"));
	}

	@Test
	public void testClone() {
		LinkedList cloneTest = (LinkedList) list.clone();
		for (int x = 0; x < list.size(); x++) {
			assertTrue(list.get(x).equals(cloneTest.get(x)));
		}
	}

	@Test
	public void testToArray() {
		Object[] arrayTest = list.toArray();
		for (int x = 0; x < list.size(); x++) {
			assertTrue(list.get(x).equals(arrayTest[x]));
		}
	}

	@Test
	public void testSet() {
		list.set(4, "fourth");
		assertTrue(list.get(4).equals("fourth"));
	}


	@Test
	public void testHasNext() {
		assertTrue(list.listIterator(list.size() + 1).hasNext() == false);
		assertTrue(list.listIterator(0).hasNext() == true);
	}

	@Test
	public void testHasPrevious() {
		assertTrue(list.listIterator(list.size() + 1).hasPrevious() == true);
		assertTrue(list.listIterator(0).hasPrevious() == false);
	}

	@Test
	public void testNext() {
		assertTrue(list.listIterator(0).next().equals("this is first"));
		assertTrue(list.listIterator(list.size() + 1).next() == null);
	}

	@Test
	public void testNextIndex() {
		assertTrue( list.listIterator(3).nextIndex() == 4);
		assertTrue( list.listIterator(list.size() +1 ).nextIndex() == -1);
	}

	@Test
	public void testPrevious() {
		assertTrue(list.listIterator(list.size() + 1).previous().equals("this is seventh"));
	}

	@Test
	public void testPreviousIndex() {
		assertTrue( list.listIterator(list.size() + 1).previousIndex() == list.size() );
		assertTrue( list.listIterator(0).previousIndex() == -1 );
	}

}
